<?php
/**
*说明：生成SQL语句，方便前台调用
*参数：$str level过滤级别列表序列
*返回：生成的SQL语句，带有and，可以直接使用
*/

function createsql($str)

{
	$newstr = explode(',',$str);
	$levelsql="";
	for($num=0;$num<count($newstr);$num++)
	{

	$pp=$num;
	if($newstr[$num]=='1')
		{
			if($levelsql=="")
				$levelsql.=$pp;
			else
				$levelsql.=",$pp";
		}
		
	}
	if($levelsql!="")
		$levelsql=" verifiy NOT IN (".$levelsql.") ";
	else
		$levelsql="";
	return $levelsql;
}


require_once 'common.inc.php';
!in_array('2',$larr)&&adminmsg('你没有被赋予操作该项的权限！');

$matches=parse_url($_SERVER['HTTP_REFERER']);
//$url=$matches['scheme'].'://'.$matches['host'].'/';

if('levellist'==$action)
{
        //读取文件内容成为一个变量
		$filename="../push/log/leveltxt.php";
		$str = file_get_contents($filename);	
		$str = explode(',',$str);
        include_once MCC_ROOT.'/templates/msystem/percolatelevel.html';
}
elseif('levelprucess'==$action)
{
        $action='levelprucess';


		$str = array_slice($_POST,0,-1);
		$str = implode(',',$str);
		
		//生成缓存文件
		$filename="../push/log/leveltxt.php";
		$fp=fopen($filename,'wb+');

		if($fp)
		{
			fwrite($fp,$str);
			fclose($fp);

			//重新生成SQL语句
                      $aaa= createsql($str);
		     // echo "生成SQL：".$aaa;
	


			//生成SQL语句文件
                	$filename="../push/log/levelsql.php";
                	$fp=fopen($filename,'wb+');

			if($fp)
                	{
                       	        fwrite($fp,$aaa);
                        	fclose($fp);
				
				adminmsg('更新内容操作成功',"percolatelevel.php?action=levellist");
			}
			else{
			
				adminmsg('更新内容操作失败1',"percolatelevel.php?action=levellist");
			}

		}
		else
			adminmsg('更新内容操作失败2',"percolatelevel.php?action=levellist");
		
		
}

?>
